package animix.blue.server.user.mapper;

import animix.blue.server.common.bean.model.RoleRight;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoleRightMapper {

    @Select({
            "<script>",
            "select * from tb_role_right where role_id in",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    public List<RoleRight> listByRoleIds(@Param("ids") Integer[] roleIds);

    @Select("select * from tb_role_right where role_id = #{roleId}")
    public List<RoleRight> listByRoleId(Integer roleId);

    @Delete("delete from tb_role_right where role_id = #{roleId}")
    public void deleteByRoleId(Integer roleId);

    @Insert({
            "<script>",
            "insert into tb_role_right (role_id, right_id, created, updated) values",
            "<foreach collection='listRoleRight' item='roleRight' index='index' separator=','>",
            "(#{roleRight.roleId}, #{roleRight.rightId}, #{roleRight.created}, #{roleRight.updated})",
            "</foreach>",
            "</script>"
    })
    public void insertBatch(@Param("listRoleRight") List<RoleRight> listRoleRight);
}
